package com.nari.ruist.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nari.common.log.annotation.Log;
import com.nari.common.log.enums.BusinessType;
import com.nari.common.security.annotation.PreAuthorize;
import com.nari.ruist.domain.RstIntype;
import com.nari.ruist.service.IRstIntypeService;
import com.nari.common.core.web.controller.BaseController;
import com.nari.common.core.web.domain.AjaxResult;
import com.nari.common.core.utils.poi.ExcelUtil;
import com.nari.common.core.web.page.TableDataInfo;

/**
 * 接口分类 Controller
 *
 * @author nari
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/intype")
public class RstIntypeController extends BaseController {
    @Autowired
    private IRstIntypeService rstIntypeService;

    /**
     * 查询接口分类 列表
     */
    @PreAuthorize(hasPermi = "system:intype:list")
    @GetMapping("/list")
    public TableDataInfo list(RstIntype rstIntype) {
        startPage();
        List<RstIntype> list = rstIntypeService.selectRstIntypeList(rstIntype);
        return getDataTable(list);
    }

    /**
     * 导出接口分类 列表
     */
    @PreAuthorize(hasPermi = "system:intype:export")
    @Log(title = "接口分类 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RstIntype rstIntype) throws IOException {
        List<RstIntype> list = rstIntypeService.selectRstIntypeList(rstIntype);
        ExcelUtil<RstIntype> util = new ExcelUtil<RstIntype>(RstIntype.class);
        util.exportExcel(response, list, "intype");
    }

    /**
     * 获取接口分类 详细信息
     */
    @PreAuthorize(hasPermi = "system:intype:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(rstIntypeService.selectRstIntypeById(id));
    }

    /**
     * 新增接口分类
     */
    @PreAuthorize(hasPermi = "system:intype:add")
    @Log(title = "接口分类 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RstIntype rstIntype) {
        return toAjax(rstIntypeService.insertRstIntype(rstIntype));
    }

    /**
     * 修改接口分类
     */
    @PreAuthorize(hasPermi = "system:intype:edit")
    @Log(title = "接口分类 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RstIntype rstIntype) {
        return toAjax(rstIntypeService.updateRstIntype(rstIntype));
    }

    /**
     * 删除接口分类
     */
    @PreAuthorize(hasPermi = "system:intype:remove")
    @Log(title = "接口分类 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(rstIntypeService.deleteRstIntypeByIds(ids));
    }
}
